package com.atguigu.auth.service.impl;

import com.atguigu.auth.mapper.SysPostMapper;
import com.atguigu.auth.service.SysPostService;
import com.atguigu.model.system.SysPost;
import com.atguigu.vo.system.SysPostQueryVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * ClassName: SysPostServiceImpl
 * Package: com.atguigu.auth.service.impl
 * Description:
 *
 * @Author: 比特张
 * @Create: 2023/9/3 - 0:44
 * @Version: v1.0
 */
@Service
public class SysPostServiceImpl extends ServiceImpl<SysPostMapper, SysPost> implements SysPostService {
    @Override
    public IPage<SysPost> pageQueryPost(Long page, Long limit, SysPostQueryVo sysPostQueryVo) {
        Page<SysPost> sysPostPage = new Page<>(page, limit);
        LambdaQueryWrapper<SysPost> wrapper = new LambdaQueryWrapper<>();

        String keyword = sysPostQueryVo.getKeyword();

        if (!StringUtils.isEmpty(keyword)) {
            wrapper.like(SysPost::getName, keyword);
        }
        if (!StringUtils.isEmpty(sysPostQueryVo.getCreateTimeEnd())) {
            //大于等于
            wrapper.ge(SysPost::getCreateTime, sysPostQueryVo.getCreateTimeEnd());
        }
        if (!StringUtils.isEmpty(sysPostQueryVo.getCreateTimeBegin())) {
            //小于等于
            wrapper.le(SysPost::getCreateTime, sysPostQueryVo.getCreateTimeBegin());
        }
        Page<SysPost> postPage = this.page(sysPostPage, wrapper);
        return postPage;
    }
}
